<template>
	<view>
		<view class="search">
			<view class="fan" @click="goto">
				<u-icon style='margin-left: 40upx;' name="arrow-left" color="gray" size="28"></u-icon>
			</view>
			<view class="sou">
				<view class="search1">
					<u-search shape="round" placeholder="输入你想要的商品名称" @search='search' :showAction="true"
						v-model="keyword" @custom='search' actionText="搜索" :animation="false"></u-search>
				</view>
			</view>
		</view>
		<view class="box" style="position: relative;">
			<view class="box_head">
				<p class="history">历史记录</p>
			</view>
			<view class="box_tags" v-for="(item,index) in tags">
				<span>{{item}}</span>
			</view>
      <u-icon @click='del()' style='position: absolute; top:2upx;right:10upx;' size=26px name="trash-fill"></u-icon>
		</view>

		<view class="joods" v-if="isTag" >
			<view class="recommend">
			<view class="productList_box_item" v-for="item in data2">
				<view class="productList_box_item_image">
					<image @click="DisGoods(item)" :src="item.url" mode=""></image>
				</view>
				<view class="productList_box_item_price_title">
					<view class="title">
						<p style='line-height:33px;'>{{item.introduce}}</p>
					</view>
					<view class="price_people">
						<p class="price"><span>￥</span>{{item.price}}</p>
						<p class="people">已有{{item.Collection}}人收藏</p>
					</view>
					<view class="user">
						<image src="http://127.0.0.1:7001/public/whj/touxiang.png" mode=""></image>
						<view class="name_people">
							<view class="name">
								<p>{{item.name}}</p>
							</view>
							<view class="people">
								<span>粉丝:{{item.fans}}</span>
								<span>关注:{{item.follow}}</span>
							</view>
						</view>
					</view>
					</view>
				</view>
			</view>
		</view>
		
		
		<view class="joods" v-if="isTag1">
			<view class="recommend">
			<view class="productList_box_item" v-for="item in searchList">
				<view class="productList_box_item_image">
					<image @click="DisGoods(item)" :src="item.url" mode=""></image>
				</view>
				<view class="productList_box_item_price_title">
					<view class="title">
						<p style='line-height:33px;'>{{item.introduce}}</p>
					</view>
					<view class="price_people">
						<p class="price"><span>￥</span>{{item.price}}</p>
						<p class="people">已有{{item.Collection}}人收藏</p>
					</view>
					<view class="user">
						<image src="http://127.0.0.1:7001/public/whj/touxiang.png" mode=""></image>
						<view class="name_people">
							<view class="name">
								<p>{{item.name}}</p>
							</view>
							<view class="people">
								<span>粉丝:{{item.fans}}</span>
								<span>关注:{{item.follow}}</span>
							</view>
						</view>
					</view>
					</view>
				</view>
			</view>
		</view>
		
		
		<!-- <u-empty v-if="show == 1" mode="search" icon="http://cdn.uviewui.com/uview/empty/search.png"> -->
		</u-empty>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				data: [],
				data2: [],
				show: 0,
				tags: ['防水劳保手套'],
				searchList:[],
				isTag:true,
				isTag1:false
			}
		},
		onLoad(options) {
			console.log(options);
			this.$api.searchShop(options.search).then(res=>{
				this.data2=res.data
			})
			
			
		},

watch:{
        keyword(){
          if(this.keyword==''){
			  this.isTag=true
			  this.isTag1=false
		  }
          }
        
},
      


		methods: {
			search() {
				this.tags.push(this.keyword)
				this.data2.forEach(item=>{
					
					if(this.keyword==item.name){
						this.isTag=false
						this.isTag1=true
						if(this.searchList.length==0){
							this.searchList.push(item)
						}else{
							this.searchList.push(item)
							this.searchList.shift(item)
						}
						console.log(this.searchList)
					}
				})
				},
			goto() {
				uni.switchTab({
					url: '/pages/Home/Home'
				})
			},
			del() {
				this.tags=[]
			},
			DisGoods(item) {
				console.log(item.id)
				uni.navigateTo({
					url: `/pages/lfyGoodsDetails1/lfyGoodsDetails1?id=${item.id}`
				})
			},
		},

	}
</script>

<style lang="scss" scoped>
	.search {
		width: 100%;
		height: 120upx;
		display: flex;
		align-items: center;
		padding: 15rpx 0;
		box-shadow: 1px 1px 4px #f8eeee;
	}

	.fan {
		width: 10%;
	}

	.search1 {
		width: 100%;
	  padding-left: 30px;
	}

	.box {
		width: 93%;
		height: 100%;
		margin: 20upx auto;
		color: #999;

		.box_head {
			width: 100%;
			height: 60upx;
			display: flex;
			justify-content: space-between;

			.history {
				color: #999;
				font-size: 36upx;
				margin-left: 22upx;
			}

			.del {
				width: 30upx;
				height: 30upx;
			}
		}

		.box_tags {
			display: inline-block;
			padding: 6upx;
			height: 30upx;
			background-color: #ddd;
			line-height: 30upx;
			color: #777;
			margin-left: 20upx;
			    font-size: 13px;	
		}
	}

	.joods {
		width: 700rpx;
		height: 100%;
		margin: auto;
		padding-bottom: 160rpx;
		overflow: hidden;

		.joods_tab {
			display: flex;
			justify-content: center;
		}

		.recommend {
			width: 100%;
			// height: 1000rpx;
			margin: auto;

			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
		}
	}

	.productList_box_item {
		width: 48%;
		height: 480upx;
		background-color: #fff;
		border-radius: 20upx;
		box-shadow: 0 0 10px #ddd;
		margin-top: 40upx;
	}

	.productList_box_item_image {
		width: 100%;
		height: 250upx;
	}

	.productList_box_item_image image {
		width: 100%;
		height: 100%;
		border-top-right-radius: 20upx;
		border-top-left-radius: 20upx;
	}

	.productList_box_item_price_title .title {
		width: 100%;
		height: 60upx;
		color: #666;
		margin-top: 10upx;
		margin-left: 20upx;
	}

	.productList_box_item_price_title .price_people {
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #ddd;
	}

	.productList_box_item_price_title .price {
		font-size: 40upx;
		color: #ff7098;
		margin-left: 20upx;
	}

	.productList_box_item_price_title .price span {
		font-size: 20upx;
		color: #ff7098;
	}

	.productList_box_item_price_title .people {
		font-size: 20upx;
		color: #999;
		margin-left: 20upx;
		margin-top: 10upx;
		margin-right: 20upx;
	}

	.productList_box_item_price_title .user {
		width: 100%;
		height: 100upx;
		display: flex;
	}

	.productList_box_item_price_title .user image {
		width: 70upx;
		height: 60upx;
		margin-top: 20upx;
		margin-left: 20upx;
	}

	.productList_box_item_price_title .user .name_people {
		width: 300upx;
		height: 100upx;
	}

	.productList_box_item_price_title .user .name_people .name {
		font-size: 20upx;
		color: #000;
		margin-left: 20upx;
		margin-top: 15upx;
	}

	.productList_box_item_price_title .user .name_people .people {
		font-size: 20upx;
		color: #999;
	}
</style>
